package com.iris.live.services.data.repositories.impl;

import com.iris.live.services.data.repositories.CrontabRepository;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.Map;
import java.util.Set;

/**
 * @Description:活动定时任务
 * @author: Tony.Zhang
 * @Date: 2017-10-06 10:14
 **/
public abstract class CrontabRepositoryImpl extends BaseRepository implements CrontabRepository {
    public CrontabRepositoryImpl() {
    }

    /**
     * 执行Native SQL 语句
     * @param statement
     * @return
     * @throws Exception
     */
    protected int executeStatement(String statement) throws Exception {
        return this.executeStatement(statement, null);
    }

    /**
     * 执行Native SQL 语句
     * @param statement
     * @param params
     * @return
     * @throws Exception
     */
    protected int executeStatement(String statement, Map<String, Object> params) throws Exception {
        Query update = this.entities.createNativeQuery(statement);
        if (params != null) {
            params.forEach((k, v) -> {
                update.setParameter(k, v);
            });
        }
        return update.executeUpdate();
    }
}
